using System.Configuration;
using System.Linq;

namespace WoltersKluwer.SPChainGang.Core.Configuration
{

    public class TemplateElementCollection : ConfigurationElementCollection
	{
		public override ConfigurationElementCollectionType CollectionType
		{
			get
			{
				return ConfigurationElementCollectionType.BasicMap;
			}
		}

		protected override ConfigurationElement CreateNewElement()
		{
            return new TemplateElement();
		}
	
		protected override object GetElementKey(ConfigurationElement element)
		{
            return ((TemplateElement)element).Name;
		}
	
		protected override string ElementName
		{
			get
			{
				return AddElementName;
			}
		}

        public TemplateElement this[int index]
		{
			get
			{
                return (TemplateElement)BaseGet(index);
			}
		}

        public TemplateElement GetByName(string name)
        {
            return this.Cast<TemplateElement>().Where(element => element.Name == name).Single();
        }
	}
}
